package modelLayer;
import java.io.Serializable;
import java.util.ArrayList;

/**
 * Singleton Container Class for the Sales Objects
 * 
 * @author Nick D. Pedersen 
 * @version 0.1
 */
public class SalesContainer implements Serializable
{
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	// instance variables - replace the example below with your own
    private static SalesContainer instance;
    private ArrayList<Sales> sales;

    /**
     * Constructor for objects of class SalesContainer
     */
    private SalesContainer()
    {
        sales = new ArrayList<Sales>();
    }
    
    /**
     * getInstance - Returns the instance of this container
     * @Return SalesContainer - Returns the instance of this container
     */
    public static SalesContainer getInstance(){
        if(instance == null){
            instance = new SalesContainer();
        }
        
        return instance;
    }

    /**
     * addSale - Adds a sale to the container
     * @Param Sales - The sale to be added to the container
     */
    public void addSale(Sales sale){
        sales.add(sale);
    }
    
    /**
     * getSales - Returns an ArrayList of all the Sales Objects
     * @Return ArrayList<Sales> - Retrun an ArrayList of Sales objects
     */
    public ArrayList<Sales> getSales(){
        return sales;
    }
    
    /**
     * clearSales - Clears the ArrayList
     */
    public void clearSales(){
        sales.clear();
    }
    
    /**
     * cancelSales - Clears the ArrayList of Sales Objects
     */
    public String cancelSales(){
        String re = "";
        String nLine = System.getProperty("line.separator");
        if(!sales.isEmpty()){
            for(Sales s : sales){
                re += s + " - Canceled!" + nLine;
                s.cancel();
            }
            sales.clear();
        }else{
            throw new NullPointerException("There are no sales to be canceled");
        }
        return re;
    }
}
